package studentinformationmanagementsystem.dao.impl;

import studentinformationmanagementsystem.dao.BaseDao;
import studentinformationmanagementsystem.dao.TemporaryClassTableDao;
import studentinformationmanagementsystem.entity.TemporaryClassTable;

import java.util.List;

/**
 * @author 苗庆
 * @version 1.0
 * 选课临时班级表dao层
 */
public class TemporaryClassTableDaolmpl extends BaseDao implements TemporaryClassTableDao {


    /**
     * 对选课临时班级表信息进行添加
     * @param temporaryClassTable  选课临时班级表对象
     * @return  受影响的记录行数
     */
    @Override
    public int insert(TemporaryClassTable temporaryClassTable) {

        String sql = "INSERT INTO `t_temporaryclasstable` (`teachersschedulesid`, `numberofpeople` ,`IsDelete`) VALUES (?, ? ,?)";
        return super.update(sql,temporaryClassTable.getTeachersschedulesid(),temporaryClassTable.getNumberofpeople(),temporaryClassTable.getIsDelete());

    }


    /**
     *  根据ID更新选课临时班级表信息
     * @param temporaryClassTable  选课临时班级表对象
     * @return 受影响的记录行数
     */
    @Override
    public int update(TemporaryClassTable temporaryClassTable) {

        String sql = "UPDATE `t_temporaryclasstable` SET `teachersschedulesid` = ? , `numberofpeople` = ? ,`IsDelete` = ? WHERE `temporaryclasstableid` = ? ";
        return super.update(sql,temporaryClassTable.getTeachersschedulesid(),temporaryClassTable.getNumberofpeople(),temporaryClassTable.getIsDelete(),temporaryClassTable.getTemporaryclasstableid());

    }


    /**
     *  根据ID删除选课临时班级表
     * @param temporaryClassTable 选课临时班级表ID
     * @return 受影响的记录行数
     */
    @Override
    public int delete(TemporaryClassTable temporaryClassTable) {

        String sql = "DELETE FROM `t_temporaryclasstable` WHERE `temporaryclasstableid` = ? AND `IsDelete`=0";
        return super.update(sql,temporaryClassTable.getTemporaryclasstableid());

    }


    /**
     * 查询所有选课临时班级表信息
     * @return 所有选课临时班级表信息
     */
    @Override
    public List<TemporaryClassTable> queryAll(TemporaryClassTable temporaryClassTable) {

        String sql = "SELECT * FROM `t_temporaryclasstable` WHERE `IsDelete` = ? ";
        return super.queryForList(TemporaryClassTable.class, sql,temporaryClassTable.getIsDelete());

    }


    /**
     * 根据选课临时班级表ID查询选课临时班级表信息
     * @param temporaryClassTable 选课临时班级表ID
     * @return 选课临时班级表信息
     */
    @Override
    public TemporaryClassTable queryById(TemporaryClassTable temporaryClassTable) {
        String sql = "SELECT * FROM `t_temporaryclasstable` WHERE `temporaryclasstableid` = ?";
        return super.queryForOne(TemporaryClassTable.class, sql, temporaryClassTable.getTemporaryclasstableid());
    }


    /**
     * 根据教师任课id查询选课临时班级表信息
     * @param temporaryClassTable 教师任课id
     * @return 选课临时班级表信息
     */
    @Override
    public TemporaryClassTable queryByTeachersschedulesid(TemporaryClassTable temporaryClassTable) {
        String sql = "SELECT * FROM `t_temporaryclasstable` WHERE `teachersschedulesid` = ? AND `IsDelete`=0";
        return super.queryForOne(TemporaryClassTable.class, sql, temporaryClassTable.getTeachersschedulesid());
    }


    /**
     * 查询总记录条数
     * @return
     */
    @Override
    public Integer queryForPageTotalCount() {
        String sql = "SELECT COUNT(1) FROM `t_temporaryclasstable` WHERE `IsDelete`=0";
        Number count = (Number) queryForSingleValue(sql);
        return count.intValue();
    }

    /**
     * 分页查询DAO层方法
     *
     * @param begin    起始记录行数
     * @param pageSize 每页展示数量
     * @return
     */
    @Override
    public List<TemporaryClassTable> queryForPageItems(int begin, int pageSize) {
        String sql = "SELECT * FROM `t_temporaryclasstable` WHERE `IsDelete`=0 LIMIT ?, ?";
        return super.queryForList(TemporaryClassTable.class, sql, begin, pageSize);
    }
}
